﻿using CNI.Repostitory.Interface;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CNI.Repository.Queue
{
    public class QueueIngestion<T> : IIngestRepository<T>
    {
        private CloudStorageAccount cloudStorageAccount = null;
        private CloudQueue cloudQueue = null;
        private string queueName = null;

        // Constructor
        public QueueIngestion(CloudStorageAccount Account, string QueueName)
        {
            this.cloudStorageAccount = Account;
            this.queueName = QueueName.ToLower();
            this.cloudQueue = cloudStorageAccount.CreateCloudQueueClient().GetQueueReference(queueName);
            this.cloudQueue.CreateIfNotExists();
        }

        public void Ingest(T Data)
        {
            CloudQueueMessage queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(Data));
            cloudQueue.AddMessage(queueMessage);
        }
    }
}
